//
//  SISSHouseConditionInfoShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/4.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSHouseConditionInfoViewController.h"
#import "SISSShowView.h"
#import "SISSUploadImageShowView.h"
#import "SISSUploadHouseConditionInfoViewController.h"
#import "SISSNetworkingManager+HouseProgress.h"
#import "SISSNetworkingManager+RentOutProgress.h"

@interface SISSHouseConditionInfoViewController ()

/// 房屋状况说明书电子档图片
@property (weak, nonatomic) SISSUploadImageShowView *contractImageShowView;
/// 房源实景照片
@property (weak, nonatomic) SISSUploadImageShowView *houseImageShowView;

/// 合同编号
@property (weak, nonatomic) SISSShowView *nameView;
/// 备注
@property (weak, nonatomic) SISSShowView *remarkView;
/// 合同截止日期
@property (weak, nonatomic) SISSShowView *licenseView;
/// 备注
@property (weak, nonatomic) SISSShowView *createDateView;

@property (weak, nonatomic) UIButton *modifyButton;

///
@property (strong, nonatomic) SISSHouseManualModel *houseManualModel;

@end

@implementation SISSHouseConditionInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"房屋状况说明书";
    
    [self requestHouseManualData];
}

- (void)requestHouseManualData {
    WeakSelf
    if (self.houseProgressModel) {
        [kNetworkManager requestHouseProgressHouseManualWithId:self.ID success:^(SISSHouseManualModel *houseManualModel) {
            
            weakSelf.houseManualModel = houseManualModel;
            weakSelf.contractImageShowView.imageUrlArr = houseManualModel.manual.mutableCopy;
            weakSelf.houseImageShowView.imageUrlArr = houseManualModel.house.mutableCopy;
            weakSelf.nameView.rightStr = houseManualModel.name;
            weakSelf.remarkView.rightStr = houseManualModel.otherdesc;
            weakSelf.licenseView.rightStr = houseManualModel.license_no;
            weakSelf.createDateView.rightStr = houseManualModel.insertTime;
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    } else {
        [kNetworkManager requestRentOutProgressLeaseManualWithId:self.ID success:^(SISSHouseManualModel *houseManualModel) {
            
            weakSelf.houseManualModel = houseManualModel;
            weakSelf.contractImageShowView.imageUrlArr = houseManualModel.manual.mutableCopy;
            weakSelf.houseImageShowView.imageUrlArr = houseManualModel.house.mutableCopy;
            weakSelf.nameView.rightStr = houseManualModel.name;
            weakSelf.remarkView.rightStr = houseManualModel.otherdesc;
            weakSelf.licenseView.rightStr = houseManualModel.license_no;
            weakSelf.createDateView.rightStr = houseManualModel.insertTime;
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
}

#pragma mark - 按钮点击事件
- (void)modifyButtonClickAction {
    SISSUploadHouseConditionInfoViewController *vc = [[SISSUploadHouseConditionInfoViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
    vc.rentOutProgressModel = self.rentOutProgressModel;
    vc.houseManualModel = self.houseManualModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.containerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
 
    SISSUploadImageShowView *contractImageShowView = [[SISSUploadImageShowView alloc] init];
    contractImageShowView.titleStr = @"房屋状况说明书电子档图片";
    [self.containerView addSubview:contractImageShowView];
    self.contractImageShowView = contractImageShowView;
    
    SISSUploadImageShowView *houseImageShowView = [[SISSUploadImageShowView alloc] init];
    houseImageShowView.titleStr = @"房源实景照片";
    [self.containerView addSubview:houseImageShowView];
    self.houseImageShowView = houseImageShowView;
    
    SISSShowView *remarkView = [[SISSShowView alloc] init];
    remarkView.isShowBottomLine = YES;
    remarkView.leftStr = @"备注";
    [self.containerView addSubview:remarkView];
    self.remarkView = remarkView;
    
    SISSShowView *nameView = [[SISSShowView alloc] init];
    nameView.isShowBottomLine = YES;
    nameView.leftStr = @"维护经纪人姓名";
    [self.containerView addSubview:nameView];
    self.nameView = nameView;
    
    SISSShowView *licenseView = [[SISSShowView alloc] init];
    licenseView.isShowBottomLine = YES;
    licenseView.leftStr = @"维护经纪人服务牌号";
    licenseView.rightStr = @"";
    [self.containerView addSubview:licenseView];
    self.licenseView = licenseView;
    
    SISSShowView *createDateView = [[SISSShowView alloc] init];
    createDateView.isShowBottomLine = YES;
    createDateView.leftStr = @"创建时间";
    createDateView.rightStr = @"";
    [self.containerView addSubview:createDateView];
    self.createDateView = createDateView;
    
    UIButton *modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [modifyButton setTitle:@"变更" forState:UIControlStateNormal];
    [modifyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [modifyButton setBackgroundColor:MAIN_COLOR];
    [modifyButton addTarget:self action:@selector(modifyButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    modifyButton.layer.cornerRadius = 4;
    modifyButton.layer.masksToBounds = YES;
    modifyButton.hidden = self.isHistory;
    [self.containerView addSubview:modifyButton];
    self.modifyButton = modifyButton;

}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGSize buttonSize = CGSizeMake(SCREEN_WIDTH * 0.8, 54);
    [self.contractImageShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
    }];
    
    [self.houseImageShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contractImageShowView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
    }];

    [self.remarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.houseImageShowView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
    }];

    [self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.remarkView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
    }];

    [self.licenseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.nameView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
    }];

    [self.createDateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.licenseView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        
//        make.bottom.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
    }];
    
    [self.modifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.createDateView.mas_bottom).offset(3 * globelMargin);
        make.centerX.equalTo(weakSelf.containerView.mas_centerX);
        make.size.mas_equalTo(buttonSize);
        make.bottom.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
    }];
    
}

@end
